<template>
  <div style="height: 100%; width: 100%; position: relative">
      <div class="pagetop">
          <div style="width: 100%">
              <table sborder="0" style=" width: 100%; font-size: 12px; white-space: nowrap; max-width: 1170px; " class="table1style" >
                  <tr>
                      <td align="right">分单类别名称</td>
                      <td width="200px"><el-input v-model="reqgroupname" size="mini" @keyup.enter.native="btnQuery()"></el-input></td>
                      <td align="right">默认采集类型</td>
                      <td width="200px">
                          <rm-ddl-common datatype="specimen" dataname="标本类型" v-model="specimencode" size="mini" width="100%"></rm-ddl-common>
                      </td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                      <td></td>
                  </tr>
              </table>
              <table style="float: right">
                  <tr>
                      <td>
                          <el-button icon="el-icon-search" type="primary" @click="btnQuery" v-has="'PINQUERY'" :disabled="changeflag">查询</el-button>
                          <el-button icon="el-icon-plus" @click="MainOpenDialog(1)" v-has="'PADD'" :disabled="changeflag">新增</el-button>
                          <el-button icon="el-icon-document" @click="SaveRecord" v-has="'PDELETE'" :disabled="!changeflag">保存</el-button>
                          <el-button icon="el-icon-close" @click="MainOpenDialog(4)" v-has="'PDELETE'" :disabled="!changeflag">取消</el-button>
                          <el-button icon="el-icon-delete" @click="MainOpenDialog(3)" v-has="'PDELETE'" :disabled="changeflag">删除</el-button>
                          <el-button icon="el-icon-download" @click="ExportCsv()" v-has="'PEXPORT'">导出</el-button>
                          <!-- <el-button icon="el-icon-upload2" @click="ImportCsv()" v-has="'PIMPORT'">导入</el-button> -->
                      </td>
                  </tr>
              </table>
          </div>
      </div>
      <div class="pagecenter">
          <rm-layout-left :fixsize="700" :splitwidth="3" :minfixsize="200" :maxflxsize="1800">
              <template v-slot:fix>
                  <vxe-table :data.sync="reqgroupData" :loading="reqgroupLoading" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row class="mytable-style" highlight-hover-column highlight-hover-row how-header-overflow ref="xTable" resizable show-overflow size="mini" stripe show-header-overflow :optimization="{ animat: false }" header-align="center" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :row-class-name="rowClassName" @current-change="currentChangeEvent" :span-method="rowspanMethod">
                      <vxe-table-column field="reqtype" sortable title="业务类别" width="55" show-overflow :formatter="FormatData" align="center"></vxe-table-column>
                      <vxe-table-column field="seq" sortable title="序号" width="40" show-overflow header-align="center" align="center"></vxe-table-column>
                      <vxe-table-column field="req_groupcode" sortable title="分单类别代码" width="85" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="req_groupname" sortable title="分单类别名称" width="120" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="tube_color" sortable title="试管颜色" width="56" show-overflow header-align="center">
                          <template v-slot="{ row }">
                              <div v-bind:style="{ background: $pub.ColorChange(row.tube_color) }" style="color: transparent">{{ row.tube_color }}</div>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="collect_tips" sortable title="采样提示" width="110" show-overflow header-align="center"></vxe-table-column>

                      <vxe-table-column field="specimen_name" sortable title="默认采集标本" width="120" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="queueseqseg" sortable title="排队号段" width="55" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="label_print_qty" sortable title="标签份数" width="55" show-overflow header-align="center" align="center"></vxe-table-column>
                      <vxe-table-column field="barcode_head" sortable title="条码前缀" width="55" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="prebarcodelen" sortable title="条码长度" width="55" show-overflow header-align="center" align="center"></vxe-table-column>
                      <vxe-table-column field="req_groupna" sortable title="类别简称" width="100" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="tuberack_color" sortable title="分拣架颜色" width="75" show-overflow header-align="center">
                          <template v-slot="{ row }">
                              <div v-bind:style="{ background: $pub.ColorChange(row.tuberack_color) }" style="color: transparent">{{ row.tuberack_color }}</div>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="sorting_tips" sortable title="分拣提示" width="110" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="labgroupname" sortable title="所属检验组" width="80" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="reportspecimenname" sortable title="报告标本类型" width="120" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="chargename" sortable title="附加费用策略" width="110" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="description" sortable title="备注说明" width="140" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="req_groupid" sortable title="分单类别ID" width="70" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="labprintflag" sortable title="检验科打印" width="70" show-overflow header-align="center" align="center">
                          <template v-slot="{ row }">
                              <el-checkbox true-label="1" false-label="0" v-model="row.labprintflag" disabled> </el-checkbox>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="packagetype" sortable title="打包类型" width="70" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="hospitalname" sortable title="医院名称" width="210" show-overflow header-align="center"></vxe-table-column>
                      <vxe-table-column field="tube_flagname" sortable title="试管标识" width="80" show-overflow header-align="center" align="center"></vxe-table-column>
                      <vxe-table-column field="mincollectqty" sortable title="最小采集量" width="90" show-overflow header-align="center" align="center"></vxe-table-column>
                      <vxe-table-column field="barrulename" sortable title="条码生成规则" width="120" show-overflow header-align="center"></vxe-table-column>

                      <vxe-table-column field="printbarcode" sortable title="预置模式下打印条码" width="120" show-overflow header-align="center" align="center">
                          <template v-slot="{ row }">
                              <el-checkbox true-label="1" false-label="0" v-model="row.printbarcode" disabled> </el-checkbox>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="showcolormodename" title="报告列表颜色显示模式" width="140" header-align="center" align="center"></vxe-table-column>
                      <vxe-table-column field="reportcolor" sortable title="显示颜色" width="56" show-overflow header-align="center">
                          <template v-slot="{ row }">
                              <div v-bind:style="{ background: $pub.ColorChange(row.reportcolor) }" style="color: transparent">{{ row.reportcolor }}</div>
                          </template>
                      </vxe-table-column>
                      <vxe-table-column field="showcolorcolumnname" title="颜色显示列" width="140" header-align="center" align="center"></vxe-table-column>
                  </vxe-table>
              </template>
              <div style="height: 100%">
                  <el-tabs @tab-click="handleTabClick" style="height:100%;" type="border-card" >
                      <el-tab-pane label="基本信息" style="overflow:auto;">
                          <el-form label-width="auto" :model="ReqGroupList" :disabled="roleJudgeFlag">
                              <table class="formtablestyle">
                                  <tr>
                                      <td width="75px">
                                          <font color="blue">类别代码：</font>
                                      </td>
                                      <td width="200px">
                                          <el-input v-model="ReqGroupList.req_groupcode" ref="input0" @keyup.enter.native="nextFocus(0)" @input="hasChange"> </el-input>
                                      </td>
                                      <td width="65px">类 别 ID：</td>
                                      <td width="200px">
                                          <el-input v-model="ReqGroupList.req_groupid" :disabled="true"> </el-input>
                                      </td>

                                  </tr>
                                  <tr>
                                      <td>
                                          <font color="blue">类别名称：</font>
                                      </td>
                                      <td>
                                          <el-input v-model="ReqGroupList.req_groupname" @blur="GetReqGroupna" ref="input2" @keyup.enter.native="nextFocus(2)" @input="hasChange"> </el-input>
                                      </td>
                                      <td>
                                          <font color="blue">类别简称：</font>
                                      </td>
                                      <td>
                                          <el-input v-model="ReqGroupList.req_groupna" maxlength="10" ref="input5" @keyup.enter.native="nextFocus(5)" @input="hasChange"></el-input>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>
                                          <font color="blue">标签份数：</font>
                                      </td>
                                      <td>
                                          <el-input v-model="ReqGroupList.label_print_qty" ref="input8" @keyup.enter.native="nextFocus(8)" @input="hasChange"> </el-input>
                                      </td>
                                      <td>
                                          <font color="blue">试管颜色：</font>
                                      </td>
                                      <td>
                                          <el-color-picker v-model="ReqGroupList.tubecolor" style="width: 100%; height: 25px" @change="hasChange"> </el-color-picker>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width="95px">默认采集标本：</td>
                                      <td width="200px">
                                          <rm-ddl-common width="100%" v-el-drag-dialog :appendtobody="true" :close-on-click-modal="false" @change="specimenchange" datatype="specimen" dataname="标本类型" ref="input1" @keyup.enter.native="nextFocus(1)" v-model="ReqGroupList.specimen_code" key="0"> </rm-ddl-common>
                                      </td>
                                      <td>默认报告标本：</td>
                                      <td>
                                          <rm-ddl-common width="100%" v-el-drag-dialog :appendtobody="true" :close-on-click-modal="false" ref="input4" @keyup.enter.native="nextFocus(4)" @change="reportspecimenchange" datatype="specimen" dataname="标本类型" v-model="ReqGroupList.reportspecimen" key="1"> </rm-ddl-common>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>周几检验：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.weekdays" ref="input3" @keyup.enter.native="nextFocus(3)" @input="hasChange"> </el-input>
                                      </td>
                                      <td>排队号段：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.queueseqseg" ref="input6" @keyup.enter.native="nextFocus(6)" @input="hasChange"> </el-input>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>采样时间字典：</td>
                                      <td>
                                          <el-select placeholder="请选择采集时间" ref="input7" @keyup.enter.native="nextFocus(7)" v-model="ReqGroupList.collectdictid" filterable clearable style="width: 100%" @change="hasChange">
                                              <el-option :key="item.value" :label="item.label" :value="item.value" v-for="item in CollectdtOptions">{{ item.label }}</el-option>
                                          </el-select>
                                      </td>
                                      <td>标本采集量：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.mincollectqty" ref="input10" @keyup.enter.native="nextFocus(10)" @input="hasChange"> </el-input>
                                      </td>
                                  </tr>
                                  <tr>

                                      <td>条码前缀：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.barcode_head" ref="input9" @keyup.enter.native="nextFocus(9)" @input="hasChange"> </el-input>
                                      </td>
                                      <td>条码长度：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.prebarcodelen" ref="input11" @keyup.enter.native="nextFocus(11)" @input="hasChange"> </el-input>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>试管标识：</td>
                                      <td>
                                          <el-select placeholder="请选择试管标识" ref="input13" @keyup.enter.native="nextFocus(13)" style="width: 100%" v-model="ReqGroupList.tube_flag" filterable clearable @change="hasChange">
                                              <el-option :key="item.value" :label="item.label" :value="item.value" v-for="item in TubeflagOptions"> {{ item.label }}</el-option>
                                          </el-select>
                                      </td>

                                      <td>标本打包类型：</td>
                                      <td>
                                          <el-select placeholder="请选择打包类型" ref="input12" @keyup.enter.native="nextFocus(12)" style="width: 100%" v-model="ReqGroupList.packagetype" filterable clearable @change="hasChange">
                                              <el-option :key="item.value" :label="item.label" :value="item.value" v-for="item in PackageOptions"> {{ item.label }}</el-option>
                                          </el-select>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>所属院区：</td>
                                      <td>
                                          <rm-ddl-common :append-to-body="true" @change="hospitalchange" datatype="hospital" dataname="医院" v-model="ReqGroupList.hospcode" ref="input15" @keyup.enter.native="nextFocus(15)" :disabled="hospdisable" width="100%"></rm-ddl-common>
                                      </td>
                                      <td>采样提示：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.collect_tips" ref="input16" @keyup.enter.native="nextFocus(16)" @input="hasChange"> </el-input>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>标签样式：</td>
                                      <td>
                                          <el-select placeholder="请选择标签样式" ref="input18" @keyup.enter.native="nextFocus(18)" style="width: 100%" v-model="ReqGroupList.barstyleid" filterable clearable @change="hasChange">
                                              <el-option :key="item.value" :label="item.label" :value="item.value" v-for="item in barstyleidList"> {{ item.label }}</el-option>
                                          </el-select>
                                      </td>
                                      <td>库位号段：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.idhead" ref="input20" @keyup.enter.native="nextFocus(20)" @input="hasChange"> </el-input>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>业务类别：</td>
                                      <td>
                                          <template>
                                              <el-radio v-model="ReqGroupList.reqtype" label="C" @change="reqtypeChange">
                                                  <font font-size="10">检验</font>
                                              </el-radio>
                                              <el-radio v-model="ReqGroupList.reqtype" label="H" @change="reqtypeChange">
                                                  <font font-size="10">输血</font>
                                              </el-radio>
                                          </template>
                                      </td>
                                      <td>附加收费策略：</td>
                                      <td>
                                          <rm-ddl-common :append-to-body="true" @change="chargechange" datatype="chargerule" dataname="附加收费策略" v-model="ReqGroupList.charge_id" ref="input14" @keyup.enter.native="nextFocus(14)" width="100%"> </rm-ddl-common>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width="40px">序号：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.seq" @input="hasChange"> </el-input>
                                      </td>
                                      <td>检验科采样：</td>
                                      <td>
                                          <el-checkbox v-model="ReqGroupList.labprintflag" size="medium" true-label="1" false-label="0" @change="hasChange"> </el-checkbox>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td width="80px">所属检验组：</td>
                                      <td>
                                          <rm-ddl-common v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" ref="input17" @keyup.enter.native="nextFocus(17)" @change="labgroupchange" datatype="labgroup" dataname="检验工作组" v-model="ReqGroupList.labgroupname" width="100%"> </rm-ddl-common>
                                      </td>
                                      <td width="120px">预置模式下打印条码：</td>
                                      <td>
                                          <el-checkbox v-model="ReqGroupList.printbarcode" size="medium" true-label="1" false-label="0" @change="hasChange"> </el-checkbox>
                                      </td>
                                  </tr>
                                  <tr>


                                      <td>条码生成规则：</td>
                                      <td>
                                          <rm-ddl-common :append-to-body="true" @change="barcoderulechange" datatype="barcoderule" dataname="条码生成规则" v-model="ReqGroupList.barrulename" ref="input19" @keyup.enter.native="nextFocus(19)" width="100%"> </rm-ddl-common>
                                      </td>
                                      <td>耗材类别：</td>
                                      <td>
                                          <el-select v-model="ReqGroupList.consumabletype" ref="input22" style="width: 100%;" @change="hasChange" filterable placeholder="请选择耗材类别" clearable>
                                              <el-option v-for="item in consumabletypeoption" :key="item.value" :label="item.label" :value="item.value"></el-option>
                                          </el-select>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>分拣架颜色：</td>
                                      <td>
                                          <el-color-picker v-model="ReqGroupList.tuberackcolor" style="width: 100%; height: 25px" @change="hasChange"> </el-color-picker>
                                      </td>
                                      <td>分拣提示：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.sorting_tips" ref="input21" @keyup.enter.native="nextFocus(16)" @input="hasChange"> </el-input>
                                      </td>

                                  </tr>
                                  <tr>
                                      <td>试管数量：</td>
                                      <td>
                                          <el-input v-model="ReqGroupList.test_tube_qty" ref="input23" @input="hasChange"></el-input>
                                      </td>
                                      <td >容器图片：</td>
                                      <td style="width:85px">
                                          <el-upload class="avatar-uploader" action="" :show-file-list="false" :auto-upload="false" :on-change="containpichange" :before-upload="imagebefore" accept="image/jpeg,image/png">
                                              <img style="height: 35px;width:80px" v-if="PicImageUrl" :src="PicImageUrl"  />
                                              <i v-else class="el-icon-plus avatar-uploader-icon1"></i>
                                          </el-upload>
                                      </td>
                                      <td style="text-align:left"><el-button icon="el-icon-view" @click="previewPic()" >预览</el-button></td>
                                  </tr>
                                  <tr>
                                      <td width="100px">报告列表颜色显示模式：</td>
                                      <td>
                                          <el-select v-model="ReqGroupList.showcolormode" style="width: 100%;" @change="hasChange">
                                              <el-option v-for="(item, index) in showmodeOption" :value="item.value" :label="item.label" :key="index"></el-option>
                                          </el-select>
                                      </td>
                                      <td>显示颜色：</td>
                                      <td>
                                          <el-color-picker v-model="ReqGroupList.reportshowcolor" style="width: 100%; height: 25px" @change="hasChange"> </el-color-picker>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td>颜色显示列：</td>
                                      <td colspan="3">
                                          <el-select v-model="ReqGroupList.showcolorcolumn" style="width: 100%;" @change="hasChange">
                                              <el-option v-for="(item, index) in showcolorcolOption" :value="item.value" :label="item.label" :key="index"></el-option>
                                          </el-select>
                                      </td>
                                  </tr>
                                  <tr>
                                      <td style="vertical-align: top">备注说明：</td>
                                      <td colspan="3">
                                          <el-input type="textarea" class="note-text" v-model="ReqGroupList.description" rows="2" @input="hasChange"> </el-input>
                                      </td>
                                  </tr>
                              </table>
                          </el-form>
                      </el-tab-pane>
                      <el-tab-pane label="采集标本类型">
                          <div style="margin-top: 1px; height: 100%; width: 100%" class="xTable1Class">
                              <vxe-table :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" :data.sync="rightData1" border show-overflow :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" height="auto" @cell-dblclick="LabqtyCellDblclick" :select-config="selectConfig" highlight-current-row highlight-hover-row ref="rigthxTable1" resizable size="mini" stripe @current-change="rigthCurrentChangeEvent" :key="specimenKey">
                                  <vxe-table-column field="specimen_code" sortable title="采集样本类型(双击)" width="120" header-show-overflow header-align="center" key="1">
                                      <template v-slot="{ row }">
                                          <rm-ddl-common ref="ddlspecimen" datatype="specimen" dataname="标本类型" @change="ddlspecimenChange()" v-model="row.specimen_code" width="100%" :readonly="true"> </rm-ddl-common>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="label_print_qty" sortable title="标签份数(可双击)" width="120" show-overflow header-align="center" align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column field="tube_color" sortable title="试管颜色" width="55" show-overflow header-align="center" align="center">
                                      <template v-slot="{ row }">
                                          <div style="height: 25px">
                                              <el-color-picker v-model="row.tubecolor" size="mini" @change="changeColorEvent(row)"> </el-color-picker>
                                          </div>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="collect_tips" sortable title="采样提示" width="80" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }" align="center"></vxe-table-column>

                                  <vxe-table-column field="tuberack_color" sortable title="分拣架颜色" width="75" show-overflow header-align="center" align="center">
                                      <template v-slot="{ row }">
                                          <div style="height: 25px">
                                              <el-color-picker v-model="row.tuberackcolor" size="mini" @change="changetubColorEvent(row)"> </el-color-picker>
                                          </div>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="sorting_tips" sortable title="分拣提示" width="80" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }" align="center"></vxe-table-column>

                                  <vxe-table-column field="containpic" sortable title="容器图片" width="60" show-overflow header-align="center" align="center">
                                      <template v-slot="{ row }">
                                          <div style="height: 25px;float:left">
                                              <el-upload class="avatar-uploader" action="" :show-file-list="false" :auto-upload="false" :on-change="rowcontainpichange" :before-upload="imagebefore" accept="image/jpeg,image/png">
                                              <img style="height: 23px;width:50px" v-if="row.containpicurl" :src="row.containpicurl"  />
                                              <i v-else class="el-icon-plus avatar-uploader-icon2"></i>
                                          </el-upload>

                                          </div>
                                          <div style="float:left"><i class="el-icon-view" style="padding: 5px 10px !important" @click="viewimage(row)"></i></div>
                                      </template>
                                  </vxe-table-column>

                                  <vxe-table-column
                                      field="charge_id"
                                      sortable
                                      title="附加收费策略"
                                      width="130"
                                      show-overflow
                                      header-align="center"
                                      align="center"
                                      :edit-render="{
                                          name: 'select',
                                          options: ChargeOptions,
                                          events: {
                                              change: (row, val) => {
                                                  row.row.charge_id = val.target.value;
                                                  hasChange();
                                              },
                                          },
                                      }"
                                  >
                                  </vxe-table-column>
                                  <vxe-table-column field="reportspecimen" sortable title="报告标本类型(双击)" width="120" header-show-overflow header-align="center" key="2">
                                      <template v-slot="{ row }">
                                          <rm-ddl-common ref="ddlreportspecimen" datatype="specimen" dataname="标本类型" v-model="row.reportspecimen" width="100%" :readonly="true" @change="ddlreportspecimenChange()"> </rm-ddl-common>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="barstyleid" sortable title="标签样式" width="100" header-align="center" :edit-render="{ name: 'input' }">
                                      <template v-slot:edit="{ row }">
                                          <el-select v-model="row.barstyleid" filterable placeholder="请选择" @change="hasChange" clearable>
                                              <el-option v-for="item in barstyleidList" :key="item.value" :label="item.label" :value="item.value"></el-option>
                                          </el-select>
                                      </template>
                                      <template v-slot="{ row }">
                                          <span>{{ getShowName(row.barstyleid, "barstyleidList") }}</span>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="barcode_head" sortable title="条码前缀" width="60" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column field="prebarcodelen" sortable title="条码长度" width="60" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column field="consumabletype" sortable title="耗材类别" width="120" header-align="center" :edit-render="{ name: 'input' }">
                                      <template v-slot:edit="{ row }">
                                          <el-select v-model="row.consumabletype" ref="input22" style="width: 100%;" @change="hasChange" filterable placeholder="请选择耗材类别" clearable>
                                              <el-option v-for="item in consumabletypeoption" :key="item.value" :label="item.label" :value="item.value"></el-option>
                                          </el-select>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="test_tube_qty" sortable title="试管数量" width="60" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column field="labprintflag" sortable title="检验科采样" width="80" show-overflow header-align="center" align="center">
                                      <template v-slot="{ row }">
                                          <el-checkbox true-label="1" false-label="0" v-model="row.labprintflag" @change="hasChange"> </el-checkbox>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="queueseqseg" sortable title="排队号段" width="60" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column field="packagetype" sortable title="标本打包类型" width="110" show-overflow header-align="center" :edit-render="{ name: 'select', options: PackageOptions, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column field="mincollectqty" sortable title="标本采集量" width="100" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column
                                      field="tube_flag"
                                      sortable
                                      title="试管标识"
                                      width="70"
                                      show-overflow
                                      header-align="center"
                                      :edit-render="{
                                          name: 'select',
                                          options: TubeflagOptions,
                                          events: {
                                              change: (row, val) => {
                                                  row.row.tube_flag = val.target.value;
                                                  hasChange();
                                              },
                                          },
                                      }"
                                  >
                                  </vxe-table-column>
                                  <vxe-table-column field="weekdays" sortable title="周几检验" width="60" show-overflow header-align="center" :edit-render="{ name: 'input', autoselect: true, events: { change: hasChange } }"> </vxe-table-column>
                                  <vxe-table-column field="antifreezing" sortable title="抗凝标本" width="60" show-overflow header-align="center" align="center">
                                      <template v-slot="{ row }">
                                          <el-checkbox true-label="1" false-label="0" v-model="row.antifreezing" @change="hasChange"> </el-checkbox>
                                      </template>
                                  </vxe-table-column>
                                  <vxe-table-column field="tubecolor" sortable title="试管颜色值" width="80" show-overflow header-align="center"> </vxe-table-column>
                                  <vxe-table-column field="tuberackcolor" sortable title="分拣架颜色值" width="80" show-overflow header-align="center"> </vxe-table-column>

                                  <vxe-table-column field="printbarcode" sortable title="预置模式下打印条码" width="120" show-overflow header-align="center" align="center">
                                      <template v-slot="{ row }">
                                          <el-checkbox true-label="1" false-label="0" v-model="row.printbarcode" @change="hasChange"> </el-checkbox>
                                      </template>
                                  </vxe-table-column>
                                  <template v-slot:fix>
                                      <div style="font-size: 18px; padding: 5px; background-color: #fff; overflow: auto;text-align:center;">
                                          <el-button @click="xTable1AddEvent" class="btnclass"> 新增明细 </el-button>
                                          <el-button @click="xTable1InsertEvent" class="btnclass"> 插入明细 </el-button>
                                          <el-button @click="xTable1DeleteEvent" class="btnclass"> 删除明细 </el-button>
                                      </div>
                                  </template>
                              </vxe-table>
                          </div>
                      </el-tab-pane>
                      <el-tab-pane label="禁止采样日期">
                          <div style="margin-top: 1px; height: 100%; width: 100%">
                              <vxe-table :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }" height="auto" header-align="center" :data.sync="rightData2" show-overflow :select-config="selectConfig" border highlight-current-row :key="sampledtkey" highlight-hover-row ref="rigthxTable2" resizable size="mini" stripe>
                                  <vxe-table-column type="index" title="NO. " width="46" align="center"> </vxe-table-column>
                                  <vxe-table-column field="nosmpdt" title="禁止采样日期 " width="220" header-align="center" :formatter="['toDateString', 'yyyy-MM-dd HH:mm:ss']">
                                      <template v-slot="{ row }">
                                          <el-date-picker v-model="row.nosmpdt" type="date" placeholder="选择日期"> </el-date-picker>
                                      </template>
                                  </vxe-table-column>
                                  <template v-slot:fix>
                                      <div style="font-size: 18px; padding: 5px; background-color: #fff; overflow: auto;text-align:center;">
                                          <el-button size="mini" @click="xTable2InsertEvent" class="btnclass"> 新 增</el-button>
                                          <el-button size="mini" @click="xTable2RemoveEvent" class="btnclass"> 删 除</el-button>
                                          <el-button size="mini" @click="ClearInvalidData" class="btnclass"> 清空过期数据</el-button>
                                          <el-button size="mini" @click="LoadHoliday" class="btnclass"> 加载其他节假日 </el-button>
                                      </div>
                                  </template>
                              </vxe-table>
                          </div>
                      </el-tab-pane>
                  </el-tabs>
              </div>
          </rm-layout-left>
      </div>

      <el-dialog title="标签打印份数（依病人类型区分）" :visible.sync="LabelPrintQtyVisialable" width="40%">
          <div style="height: 300px">
              <vxe-table show-overflow ref="xLabelPrintQty" class="mytable-style" height="auto" :loading="loading" :select-config="{ reserve: true }" :cell-class-name="CellClassName" :sort-config="{ trigger: 'cell' }" :keyboard-config="keyConfig" :keyboard-local-config="keyLocalConfig" :mouse-config="{ selected: true }" :data.sync="PopTableData3" border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe :edit-config="{ trigger: 'click', mode: 'cell', showStatus: true, showIcon: false }">
                  <vxe-table-column type="index" title="NO." width="50" align="center"></vxe-table-column>
                  <vxe-table-column field="specimen_name" title="标本类型" width="140" sortable header-align="center"> </vxe-table-column>
                  <vxe-table-column field="pat_typecode" title="病人类型" width="140" header-align="center" align="center" :edit-render="{ name: 'select', options: patTypeOptions }"> </vxe-table-column>
                  <vxe-table-column field="label_print_qty" title="标签份数" width="108" sortable header-align="center" align="center" :edit-render="{ name: 'input', autoselect: true }"></vxe-table-column>
              </vxe-table>
          </div>
          <span slot="footer" class="dialog-footer">
              <el-button @click="LabelPrintQtyInsert">新 增</el-button>
              <el-button @click="LabelPrintQtyDelete">删 除</el-button>
              <el-button @click="LabelPrintQtySave">确 定</el-button>
              <el-button @click="LabelPrintQtyVisialable = false">取 消</el-button>
          </span>
      </el-dialog>

      <el-dialog title="提示" :visible.sync="dialogDelVisible" width="30%">
          <span class="el-icon-info"
              >确定删除分单类别名称为<b style="color: red">{{ message }}</b
              >的记录吗？</span
          >
          <span slot="footer" class="dialog-footer">
              <el-button @click="ConfirmDel">确 定</el-button>
              <el-button @click="dialogDelVisible = false" :autofocus="true">取 消</el-button>
          </span>
      </el-dialog>
      <el-dialog title="图片预览" :visible.sync="imagedialogVisible" width="500px">
          <div class="demo-image__preview">
              <el-image
                  style="width: 500px; height: 600px"
                  :src="imageurl"
                  :preview-src-list="srcList">
              </el-image>
          </div>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "MNG241",
  data() {
      return {
          sampledtkey: 0,
          specimenKey: 0,
          // selrow: "",
          selrow: {},
          operatetype: 2, //1:新增 2:修改 3:删除
          specimencode: "",
          message: "",
          reqgroupid_key: 0,
          reqgroupLoading: false,
          loading: false,
          LabelPrintQtyVisialable: false,
          dialogDelVisible: false,
          reqgroupData: [],
          fallData: [],
          allReq_groupcodeList: [],
          allReq_groupidList: [],
          roleJudgeFlag: false, // 判断是否有修改权限
          ReqGroupList: {},
          TempPopReqGroupList: {},
          tableColumn: [],
          tableDataColumn1: [],
          rightDataColumn1: [],
          rightDataColumn2: [],
          rightData1: [],
          rightData2: [],
          PopTableData3: [],
          PackageOptions: [],
          CollectdtOptions: [],
          TubeflagOptions: [],
          ChargeOptions: [],
          patTypeOptions: [],
          SpecimenOptions: [],
          barstyleidList: [],
          barstyleidListMap: [],
          hospdisable: false,
          ModData: [],
          AddData: [],
          utype: this.$tool.getSession(this.$tool.loginutype),
          hospcode: this.$tool.getSession(this.$tool.selectedhis),
          keyConfig: {
              isEdit: true,
          },
          keyLocalConfig: {
              isArrow: true,
              isDel: true,
              isTab: true,
          },
          selectConfig: {
              reserve: true,
          },
          changeflag: false,
          focusIndex: 0,
          clickRow: {},
          consumabletypeoption:[],
          TempPicImageUrl:"",
          PicImageUrl:"",
          srcList:[],
          imagedialogVisible:false,
          imageurl:"",
          specimencode: "",
          reqgroupname: "",
          showmodeOption: [{value: "0", label: "不变色"},{value: "1", label: "改变底色"},{value: "2", label: "改变字体颜色"}],
          showcolorcolOption: [{value: "1", label: "分单类别"},{value: "2", label: "整行"}],
      };
  },
  created() {
      this.initPage();
      this.ddlInitData(); //初始化下拉框的数据
      this.ClearBag(); //页面打开时清除垃圾数据
      this.$ddldata.IsAreaModeFun().then((r) => {
          if (this.$tool.getSession(this.$tool.loginutype) != "G") {
              //普通用户
              this.hospdisable = true;
          } else {
              this.hospdisable = false;
          }
      });
  },
  mounted() {},
  updated() {},
  methods: {
      btnQuery() {
          this.AddData = [];
          this.ModData = [];
          this.initPage();
      },
      //主表初始化
      initPage() {
          var that = this;
          that.reqgroupLoading = true;
          that.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "query",
                      reqgroup: this.reqgroup,
                      specimencode: this.specimencode,
                      reqgroupname: this.reqgroupname,
                  },
              })
              .then((res) => {
                  that.reqgroupLoading = false;
                  if (res.Data.length > 0) {
                      that.reqgroupData = res.Data; //主表赋值
                      that.selrow = res.Data[0];
                      that.$refs.xTable.setCurrentRow(that.selrow);
                      if (that.utype != "G" && that.ReqGroupList.hospcode == "All") {
                          that.roleJudgeFlag = true;
                      }
                      that.QueryRight();
                  } else {
                      that.reqgroupData = [];
                      that.ReqGroupList = {};
                      that.rightData1 = [];
                      that.rightData2 = [];
                      that.selrow.req_groupid = "";
                  }
              })
              .catch((e) => {
                  this.$alert(e, "出错");
              });
      },
      //明细查询
      QueryRight() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "QueryRight",
                      req_groupid: this.selrow.req_groupid,
                  },
              })
              .then((res) => {
                  //采样标本类型的数据
                  res.RData.Data.forEach((item) => {
                      item.tubecolor = this.$pub.ColorChange(item.tube_color); //转为带#的颜色
                      console.info("item.tuberack_color==" + item.tuberack_color);
                      if (item.tuberack_color == null) {
                          item.tuberackcolor = "#ffffff"; //转为带#的颜色
                      } else {
                          item.tuberackcolor = this.$pub.ColorChange(item.tuberack_color); //转为带#的颜色
                      }
                  });
                  this.rightData1 = res.RData.Data; //弹窗采集标本类型数据集

                  //禁止采样时间的数据
                  this.rightData2 = res.RData2.Data; //弹窗页面禁止采样时间数据集
                  //右边form表单数据
                  res.Data[0].tubecolor = this.$pub.ColorChange(res.Data[0].tube_color);
                  if (res.Data[0].tuberack_color == null) {
                      res.Data[0].tuberackcolor = "#ffffff";
                  } else {
                      res.Data[0].tuberackcolor = this.$pub.ColorChange(res.Data[0].tuberack_color);
                  }

                  if (res.Data[0].reportcolor == null) {
                      res.Data[0].reportshowcolor = "#ffffff";
                  } else {
                      res.Data[0].reportshowcolor = this.$pub.ColorChange(res.Data[0].reportcolor);
                  }
                  this.ReqGroupList = XEUtils.clone(res.Data[0], true);
                  this.TempPopReqGroupList = XEUtils.clone(this.ReqGroupList, true);
                  this.PicImageUrl = res.containpic;
                  console.info("this.PicImageUrl111=="+this.PicImageUrl);
                  this.TempPicImageUrl = XEUtils.clone(this.PicImageUrl, true);
              });
      },
      FormatData({ cellValue, row, column }) {
          if (column.property == "reqtype") {
              if (row.reqtype == "C") {
                  return "检验";
              } else if (row.reqtype == "H") {
                  return "输血";
              } else {
                  return cellValue;
              }
          } else if (column.property == "nosmpdt") {
              return XEUtils.toDateString(cellValue, "yyyy-MM-dd");
          } else {
              return cellValue;
          }
      },
      rigthCurrentChangeEvent({ row }) {
          this.specimencode = row.specimen_code;
      },
      currentChangeEvent({ row, column }) {
          if (this.changeflag) {
              //如果值有改变，禁止换行
              this.$refs.xTable.setCurrentRow(this.selrow);
              return false;
          } else {
              this.changeflag = false;
              this.selrow = row;
              this.QueryRight();
          }
      },
      hasChange() {
          this.changeflag = true;
      },
      xTable1AddEvent() {
          let color = "#ffffff";
          if (this.ReqGroupList.tuberackcolor != "" && this.ReqGroupList.tuberackcolor != null && this.ReqGroupList.tuberackcolor !== "transparent") {
              color = this.ReqGroupList.tuberackcolor;
          }

          //采集标本类型新增
          this.$refs.rigthxTable1
              .insert({
                  label_print_qty: 1,
                  test_tube_qty: 1,
                  tubecolor: this.ReqGroupList.tubecolor,
                  tube_color: this.$pub.ColorTrans(this.ReqGroupList.tubecolor.split("#")[1]),
                  tuberackcolor: color,
                  tuberack_color: this.$pub.ColorTrans(color.split("#")[1]),
                  containpicurl:"",
                  containpic_type:"",
                  containpic:""
              })
              .then(({ row }) => {
                  this.$nextTick(() => {
                      this.$refs.rigthxTable1.setCurrentRow(row);
                      this.$refs.rigthxTable1.setActiveRow(row);
                  });
              });
          this.hasChange();
      },
      xTable1InsertEvent() {
          //采集标本类型插入
          let row = this.$refs.rigthxTable1.getCurrentRow();
          let color = "#ffffff";
          if (this.ReqGroupList.tuberackcolor != "" && this.ReqGroupList.tuberackcolor != null && this.ReqGroupList.tuberackcolor !== "transparent") {
              color = this.ReqGroupList.tuberackcolor;
          }

          if (row) {
              this.$refs.rigthxTable1
                  .insertAt(
                      {
                          label_print_qty: 1,
                          tubecolor: this.ReqGroupList.tubecolor,
                          tube_color: this.$pub.ColorTrans(this.ReqGroupList.tubecolor.split("#")[1]),
                          tuberackcolor: color,
                          tuberack_color: this.$pub.ColorTrans(color.split("#")[1]),
                          containpicurl:"",
                          containpic_type:"",
                          containpic:""
                      },
                      row
                  )
                  .then(({ row }) => {
                      this.$refs.rigthxTable1.setCurrentRow(row);
                      this.$refs.rigthxTable1.setActiveRow(row);
                  });
          } else {
              this.$refs.rigthxTable1
                  .insert({
                      label_print_qty: 1,
                      tube_color: 255,
                      tuberack_color: 255,
                  })
                  .then(({ row }) => {
                      this.$refs.rigthxTable1.setCurrentRow(row);
                      this.$refs.rigthxTable1.setActiveRow(row);
                  });
          }
          this.hasChange();
      },
      //采集标本类型删除
      xTable1DeleteEvent() {
          try {
              var delrow = this.$refs.rigthxTable1.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.rigthxTable1.getTableData().fullData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.rigthxTable1.remove(delrow);
                  let havedata = this.$refs.rigthxTable1.getTableData().fullData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.rigthxTable1.setCurrentRow(selectrow);
                  }
                  this.hasChange();
              } else {
                  this.$message({
                      message: "请先选中要删除的明细！",
                      type: "warning",
                  });
              }
          } catch (e) {
              alert(e);
          }
      },
      // 回车切换输入框
      nextFocus(index) {
          if (index > 17) return false;
          var that = this;
          var focusIndex = index + 1;
          setTimeout(function () {
              if (index == 7 || index == 12 || index == 13 || index == 17) {
                  that.$refs["input" + index].blur();
              }
              if (index == 15) {
                  that.$refs["input" + index].$refs.ddlmainSelect.blur();
              }
              that.$refs["input" + focusIndex].focus();
          }, 1);
      },
      hospitalchange() {
          //所属院区
          this.hasChange();
      },
      barcoderulechange(id, name) {
          //条码生成规则
          this.ReqGroupList.barruleid = id;
          this.ReqGroupList.barrulename = name;
          this.hasChange();
      },
      specimenchange(code, name) {
          //默认采集标本
          this.ReqGroupList.specimen_code = code;
          this.ReqGroupList.specimen_name = name;
          this.ReqGroupList.reportspecimen = code;
          this.ReqGroupList.reportspecimenname = name;
          this.hasChange();
      },
      reportspecimenchange(code, name) {
          //默认报告标本
          this.ReqGroupList.reportspecimen = code;
          this.ReqGroupList.reportspecimenname = name;
          this.hasChange();
      },
      labgroupchange(code, name) {
          //检验工作组
          this.ReqGroupList.labgroupid = code;
          this.ReqGroupList.labgroupname = name;
          this.hasChange();
      },
      //标签份数弹窗
      LabqtyCellDblclick({ row, column }) {
          this.clickRow = row;
          if (this.operatetype == "1") {
              this.$message.warning("请先保存后再设定标签明细份数！");
          } else if (this.operatetype == "2") {
              if (column.property == "label_print_qty") {
                  if (row.specimen_code) {
                      this.LabelPrintQtyVisialable = true;
                      this.ReqGroupLabelQuery();
                  } else {
                      this.$message.warning("请先选择采集样本类型！");
                  }
              }
          }
      },
      //标签份数查询
      ReqGroupLabelQuery() {
          this.loading = true;
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "ReqGroupLabelQuery",
                      reqgroupid: this.ReqGroupList.req_groupid,
                      specimencode: this.specimencode,
                  },
              })
              .then((response) => {
                  this.PopTableData3 = response;
                  this.loading = false;
              })
              .catch((e) => {
                  this.$alert(e, "error");
                  this.loading = false;
              });
      },
      MainOpenDialog(k) {
          if (k == 1) {
              //新增
              this.ReqGroupList = {
                  req_groupid: "",
                  specimen_code: "",
                  reportspecimen: "",
                  barruleid: "",
                  tubecolor: "#FF0000",
                  tuberackcolor: "#FFFFFF",
                  reportshowcolor: "#FFFFFF",
                  reqtype: "C",
                  label_print_qty: 1,
                  test_tube_qty: 1,
                  req_groupna: "",
                  hospcode: this.$ddldata.IsAreaMode ? this.hospcode : "All",
              };
              this.rightData1 = [];
              this.rightData2 = [];
              this.operatetype = 1;
              this.$refs.input0.focus();
              this.hasChange();
          } else if (k == 4) {
              //取消
              this.changeflag = false;
              this.operatetype = "2";
              // 空数据时不查询右侧表格
              if (this.reqgroupData.length == 0) {
                  this.ReqGroupList = {};
                  this.rightData1 = [];
                  this.rightData2 = [];
              } else {
                  this.QueryRight();
              }
          } else {
              // 删除
              if (this.utype != "G" && this.ReqGroupList.hospcode == "All") {
                  this.$alert("您不是管理员，不能删除医院代码为All的数据！", "提示", {
                      confirmButtonText: "确定",
                  });
                  return false;
              } else {
                  this.message = this.selrow.req_groupname;
                  this.dialogDelVisible = true;
              }
          }
      },
      // 确认删除
      ConfirmDel() {
          this.dialogDelVisible = false;
          this.operatetype = "3";
          this.SaveRecord();
      },
      xTable2InsertEvent() {
          //禁止采样时间新增
          this.$refs.rigthxTable2.insert().then(({ row }) => {
              this.$nextTick(() => {
                  this.$refs.rigthxTable2.setCurrentRow(row);
                  // this.$refs.rigthxTable2.setActiveRow(row);
              });
          });
          this.hasChange();
      },
      xTable2RemoveEvent() {
          //禁止采样时间删除
          try {
              var delrow = this.$refs.rigthxTable2.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.rigthxTable2.getTableData().fullData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.rigthxTable2.remove(delrow);
                  let havedata = this.$refs.rigthxTable2.getTableData().fullData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.rigthxTable2.setCurrentRow(selectrow);
                  }
                  this.hasChange();
              } else {
                  this.$message({
                      message: "请先选中要删除的明细！",
                      type: "warning",
                  });
              }
          } catch (e) {
              this.$alert(e, "出错");
          }
      }, //初始化所有下拉框
      ddlInitData() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "ddlInitData",
                  },
              })
              .then((res) => {
                  this.PackageOptions = res.PackageData;
                  this.CollectdtOptions = res.CollectdtData;
                  this.TubeflagOptions = res.TubeflagData;
                  this.ChargeOptions = res.ChargeData;
                  this.patTypeOptions = res.PatTypeData;
                  this.SpecimenOptions = res.SpeimenData;
                  this.barstyleidList = res.barstyleid;
                  this.consumabletypeoption = res.consumabletypeData;
                  this.barstyleidListMap = this.$pub.arrayToMap(this.barstyleidList, "value", "label");
              })
              .catch((e) => {
                  this.$alert(e, "error");
              });
      },
      //判断是否存在输血
      GetHTime() {
          let AllData = this.$refs.xTable.getTableData().fullData;
          let data = AllData.find((m) => m.reqtype == "H");
          if (!!data) {
              //找到
              return { Htime: "true", Req_GroupID: data.req_groupid };
          } else {
              return { Htime: "false", Req_GroupID: "" };
          }
      },
      reqtypeChange() {
          let result = this.GetHTime();
          this.changeflag = true;
          if (this.ReqGroupList.reqtype == "H") {
              if (this.operatetype == 1) {
                  //新增
                  if (result.Htime == "true") {
                      //原来的数据中存在输血
                      this.$alert("输血类分单类别只可以出现一次，系统发现已存在输血类的分单类别，所以当前分单类别不可以再使用输血类", "提示", {
                          confirmButtonText: "确定",
                          callback: (action) => {
                              this.ReqGroupList.reqtype = "C";
                          },
                      });
                  }
              } else {
                  //修改
                  if (result.Htime == "false" && result.Req_GroupID != this.ReqGroupList.req_groupid) {
                  } else if (result.Htime == "true" && result.Req_GroupID == this.ReqGroupList.req_groupid) {
                      //输血--先切换检验在切换输血
                  } else {
                      //原来的数据中存在输血
                      this.$alert("输血类分单类别只可以出现一次，系统发现已存在输血类的分单类别，所以当前分单类别不可以再使用输血类", "提示", {
                          confirmButtonText: "确定",
                          callback: (action) => {
                              this.ReqGroupList.reqtype = "C";
                          },
                      });
                  }
              }
          }
      },
      //主表及明细操作保存
      SaveRecord() {
          var that = this;
          if (!that.ReqGroupList.tubecolor) that.ReqGroupList.tubecolor = "#FFFFFF";
          if (that.ReqGroupList.tubecolor.indexOf("#") > -1) {
              //如果是十六进制颜色
              let popcolor = that.ReqGroupList.tubecolor.split("#")[1];
              that.ReqGroupList.tube_color = that.$pub.ColorTrans(popcolor);
          }
          if (!that.ReqGroupList.tuberackcolor) that.ReqGroupList.tuberackcolor = "#FFFFFF";
          if (that.ReqGroupList.tuberackcolor.indexOf("#") > -1) {
              //如果是十六进制颜色
              let tucolor = that.ReqGroupList.tuberackcolor.split("#")[1];
              that.ReqGroupList.tuberack_color = that.$pub.ColorTrans(tucolor);
          }
          if (!that.ReqGroupList.reportshowcolor) that.ReqGroupList.reportshowcolor = "#FFFFFF";
          if (that.ReqGroupList.reportshowcolor.indexOf("#") > -1) {
              //如果是十六进制颜色
              let reportcolor = that.ReqGroupList.reportshowcolor.split("#")[1];
              that.ReqGroupList.reportcolor = that.$pub.ColorTrans(reportcolor);
          }

          // delete eval(this.ReqGroupList).tubecolor;
          let RTableData1 = "";
          let RTableData2 = "";
          if (this.operatetype != 3) {
              //非删除操作
              RTableData1 = that.$refs.rigthxTable1.getRecordset();
              RTableData2 = that.$refs.rigthxTable2.getRecordset();
              let specArr = [];
              let jsonObj = that.$refs.rigthxTable1.getTableData().fullData;
              jsonObj.forEach((item) => {
                  specArr.push(item.specimen_code);
              });
              if (that.ReqGroupList.specimen_code && that.ReqGroupList.specimen_code != "") {
                  //如果默认采集标本有取值
                  if (specArr.indexOf(that.ReqGroupList.specimen_code) < 0) {
                      //如果明细资料中如果没有该“采集标本类型”
                      that.$nextTick(() => {
                          RTableData1.insertRecords.push({
                              specimen_code: that.ReqGroupList.specimen_code,
                              label_print_qty: 1,
                              test_tube_qty: 1,
                              tube_color: that.ReqGroupList.tube_color,
                              tuberack_color: that.ReqGroupList.tuberack_color,
                              reportspecimen: that.ReqGroupList.specimen_code,
                          });
                      });
                  }
              }
          }

          that.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "SaveRecord",
                      utype: that.operatetype,
                      req_groupid: that.ReqGroupList.req_groupid,
                      Nformdata: that.ReqGroupList,
                      OformData: that.operatetype == 2 ? that.TempPopReqGroupList : "",
                      TableData1: RTableData1,
                      TableData2: RTableData2,
                  },
              })
              .then((response) => {
                  if (response.errcode == "1") {
                      that.changeflag = false;
                      that.reqgroupid_key = response.keyid;
                      that.$pub.message(that, "保存成功！", "success");
                      if (that.operatetype == "1") {
                          //新增数据成功后的不刷新操作
                          if (that.AddData.indexOf(response.keyid) == -1) {
                              that.AddData.push(response.keyid);
                          }
                          that.ReqGroupList.req_groupid = XEUtils.clone(that.reqgroupid_key, true);
                          that.$refs.xTable.insert(that.ReqGroupList).then(({ row }) => {
                              that.setHightLightRow();
                              that.selrow = row;
                              that.QueryRight();
                          });
                          that.operatetype = 2;
                      } else if (that.operatetype == "2") {
                          //修改数据成功后的不刷新操作
                          if (that.ModData.indexOf(response.keyid) < 0) {
                              that.ModData.push(response.keyid);
                          }
                          that.updateTableCurrentRow();
                          that.QueryRight();
                      } else {
                          //删除
                          let delrow = this.$refs.xTable.getCurrentRow();
                          if (delrow) {
                              var alldatd = this.$refs.xTable.getTableData().fullData;
                              var rowindex = alldatd.indexOf(delrow);
                              this.$refs.xTable.remove(delrow);
                              let havedata = this.$refs.xTable.getTableData().fullData;
                              if (havedata.length > 0) {
                                  if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                                  let selectrow = havedata[rowindex];
                                  this.$refs.xTable.setCurrentRow(selectrow);
                                  this.selrow = selectrow;
                                  this.QueryRight();
                                  setTimeout(() => {
                                      this.$refs.xTable.scrollToRow(selectrow);
                                  }, 10);
                              } else {
                                  this.$refs.xTable.setCurrentRow(null);
                                  this.tableData = [];
                                  this.ReqGroupList = {};
                              }
                          }
                          that.operatetype = "2";
                      }
                  } else {
                      that.$alert("操作失败！" + response.errmsg, "提示");
                  }
              })
              .catch((e) => {
                  this.$alert(e, "出错");
              });
      },
      updateTableCurrentRow() {
          this.selrow.req_groupcode = this.ReqGroupList.req_groupcode;
          this.selrow.req_groupname = this.ReqGroupList.req_groupname;
          this.selrow.tube_color = this.ReqGroupList.tube_color;
          this.selrow.specimen_name = this.ReqGroupList.specimen_name;
          this.selrow.queueseqseg = this.ReqGroupList.queueseqseg;
          this.selrow.label_print_qty = this.ReqGroupList.label_print_qty;
          this.selrow.barcode_head = this.ReqGroupList.barcode_head;
          this.selrow.prebarcodelen = this.ReqGroupList.prebarcodelen;
          this.selrow.req_groupna = this.ReqGroupList.req_groupna;
          this.selrow.collect_tips = this.ReqGroupList.collect_tips;
          this.selrow.labgroupname = this.ReqGroupList.labgroupname;
          this.selrow.reportspecimenname = this.ReqGroupList.reportspecimenname;
          this.selrow.chargename = this.ReqGroupList.chargename;
          this.selrow.description = this.ReqGroupList.description;
          this.selrow.req_groupid = this.ReqGroupList.req_groupid;
          this.selrow.labprintflag = this.ReqGroupList.labprintflag;
          this.selrow.packagetype = this.ReqGroupList.packagetype;
          this.selrow.hospitalname = this.ReqGroupList.hospitalname;
          this.selrow.tube_flag = this.ReqGroupList.tube_flag;
          this.selrow.mincollectqty = this.ReqGroupList.mincollectqty;
          this.selrow.seq = this.ReqGroupList.seq; //添加序号
          this.selrow.barrulename = this.ReqGroupList.barrulename;
          this.selrow.printbarcode = this.ReqGroupList.printbarcode;
          this.selrow.tuberack_color = this.ReqGroupList.tuberack_color;
          this.selrow.sorting_tips = this.ReqGroupList.sorting_tips;

          this.$refs.xTable.updateListenter();
          this.setHightLightRow();
      }, //修改或新增后选中行
      setHightLightRow() {
          let row = this.$refs.xTable.getTableData().fullData.find((m) => m.req_groupid == this.reqgroupid_key);
          if (!!row) {
              setTimeout(() => {
                  this.$refs.xTable.scrollToRow(row);
                  this.$refs.xTable.setCurrentRow(row);
              }, 10);
          }
      },
      //清理垃圾数据
      ClearBag() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "ClearBag",
                  },
              })
              .then((response) => {
                  if (response.errcode == "0") {
                      this.$message({
                          message: response.errmsg,
                          type: "warning",
                      });
                  }
              })
              .catch((e) => {
                  this.$alert(e, "error");
              });
      },
      //清理过期数据
      ClearInvalidData() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "ClearInvalidData",
                  },
              })
              .then((response) => {
                  if (response.errcode == "0") {
                      this.$message({
                          message: response.errmsg,
                          type: "warning",
                      });
                  } else {
                      this.hasChange();
                      this.$message({
                          message: response.errmsg,
                          type: "success",
                      });
                  }
              })
              .catch((e) => {
                  this.$alert(e, "error");
              });
      },
      //加载节假日
      LoadHoliday() {
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "LoadHoliday",
                      req_groupid: this.ReqGroupList.req_groupid,
                  },
              })
              .then((res) => {
                  if (res.errcode == "0") {
                      this.$message({
                          message: res.errmsg,
                          type: "warning",
                      });
                  } else {
                      this.hasChange();
                      let pagedata = this.$refs.rigthxTable2.getTableData().fullData;
                      res.forEach((item) => {
                          let startdate = XEUtils.toDateString(item.startdate);
                          if (pagedata.length > 0) {
                              for (var i = 0; i < pagedata.length; i++) {
                                  if (pagedata[i].nosmpdt.indexOf(startdate) > -1) {
                                  } else {
                                      this.$refs.rigthxTable2.insert({ nosmpdt: startdate });
                                  }
                              }
                          } else {
                              this.$refs.rigthxTable2.insert({ nosmpdt: startdate });
                          }
                      });
                      this.$message({
                          message: "节假日加载成功",
                          type: "success",
                      });
                  }
              })
              .catch((e) => {
                  this.$alert(e, "error");
              });
      },
      //简称
      GetReqGroupna() {
          if (this.ReqGroupList.req_groupna != "" && this.ReqGroupList.req_groupname) {
              return false;
          } else {
              let groupname = XEUtils.clone(this.ReqGroupList.req_groupname, true);
              if (groupname.length > 4) {
                  this.ReqGroupList.req_groupna = groupname.substring(0, 4);
              } else {
                  this.ReqGroupList.req_groupna = groupname;
              }
          }
          // }
      },
      //标签分数保存/删除/新增
      LabelPrintQtySave() {
          let xLabelPrintQty = this.$refs.xLabelPrintQty.getRecordset();
          this.$tool
              .request({
                  url: "MNG/MNG2/MNG241",
                  method: "post",
                  data: {
                      action: "save",
                      reqgroupid: this.ReqGroupList.req_groupid,
                      specimencode: this.specimencode,
                      urec: xLabelPrintQty,
                  },
              })
              .then((response) => {
                  if (response.errcode == "1") {
                      this.$message({
                          message: "操作成功！",
                          type: "success",
                      });
                      this.LabelPrintQtyVisialable = false;
                  } else {
                      this.$message({
                          message: "保存失败！" + response.errmsg,
                          type: "warning",
                      });
                  }
              })
              .catch((e) => {
                  this.$alert(e, "出错");
              });
      },
      LabelPrintQtyDelete() {
          try {
              var delrow = this.$refs.xLabelPrintQty.getCurrentRow();
              if (delrow) {
                  var alld = this.$refs.xLabelPrintQty.getTableData().fullData;
                  var rowindex = alld.indexOf(delrow);
                  this.$refs.xLabelPrintQty.remove(delrow);
                  let havedata = this.$refs.xLabelPrintQty.getTableData().fullData;
                  if (havedata.length > 0) {
                      if (rowindex >= havedata.length) rowindex = havedata.length - 1;
                      let selectrow = havedata[rowindex];
                      this.$refs.xLabelPrintQty.setCurrentRow(selectrow);
                  }
              } else {
                  this.$message({
                      message: "请先选中要删除的明细！",
                      type: "warning",
                  });
              }
          } catch (e) {
              alert(e);
          }
      },
      LabelPrintQtyInsert() {
          let data = this.$refs.xLabelPrintQty.tableData;
          let insertData = {};
          if (data.length == 0) {
              insertData = { pat_typecode: "1", label_print_qty: "1" };
          } else if (data.length == 1) {
              insertData = { pat_typecode: "3", label_print_qty: "1" };
          } else if (data.length == 2) {
              insertData = { pat_typecode: "4", label_print_qty: "1" };
          } else {
              insertData = { pat_typecode: "", label_print_qty: "1" };
          }
          this.$refs.xLabelPrintQty.insert(insertData).then(({ row }) => {
              this.$nextTick(() => {
                  this.$refs.xLabelPrintQty.setCurrentRow(row);
                  this.$refs.xLabelPrintQty.setActiveRow(row);
              });
          });
      },
      ExportCsv() {
          this.$refs.xTable.exportCsv({ filename: "项目分单类别" });
      },
      ImportCsv() {
          //this.$pub.testfunction();
      },
      ddlreportspecimenChange() {
          this.hasChange();
      },
      ddlspecimenChange(code, name) {
          this.clickRow.reportspecimen = XEUtils.clone(this.clickRow.specimen_code, true);
          this.hasChange();
      },
      chargechange(id, name) {
          //附加收费策略
          this.ReqGroupList.chargename = name;
          this.ReqGroupList.charge_id = id;
          this.hasChange();
      },
      changeColorEvent(row) {
          let color = row.tubecolor.split("#")[1];
          if (!!color) {
              row.tube_color = this.$pub.ColorTrans(color);
              this.hasChange();
          }
      },
      changetubColorEvent(row) {
          let color = row.tuberackcolor.split("#")[1];
          if (!!color) {
              row.tuberack_color = this.$pub.ColorTrans(color);
              this.hasChange();
          }
      },
      //tab切换
      handleTabClick(tab, event) {
          if (tab.label == "基本信息") {
              this.specimenKey = this.specimenKey + 1;
          }
          if (tab.label == "采集标本类型") {
              this.specimenKey = this.specimenKey + 1;
          }
          if (tab.label == "禁止采样日期") {
              this.sampledtkey = this.sampledtkey + 1;
          }
      },
      //申请类别合并
      rowspanMethod({ row, $rowIndex, column, data }) {
          let fields = ["reqtype"];
          let cellValue = row[column.property];
          if (cellValue && fields.includes(column.property)) {
              let prevRow = data[$rowIndex - 1];
              let nextRow = data[$rowIndex + 1];
              if (prevRow && prevRow[column.property] === cellValue) {
                  return { rowspan: 0, colspan: 0 };
              } else {
                  let countRowspan = 1;
                  while (nextRow && nextRow[column.property] === cellValue) {
                      nextRow = data[++countRowspan + $rowIndex];
                  }
                  if (countRowspan > 1) {
                      return { rowspan: countRowspan, colspan: 1 };
                  }
              }
          }
      },
      //标签份数弹窗
      CellClassName({ columnIndex }) {
          if (columnIndex == "1" || columnIndex == "0") {
              return "col-orange";
          } else {
              return "";
          }
      },
      //主表
      rowClassName({ row, rowIndex }) {
          if (this.AddData.indexOf(row.req_groupid) > -1) {
              return "row-new";
          }
          if (this.ModData.indexOf(row.req_groupid) > -1) {
              return "row-modify";
          }
      },
      getShowName(code, list) {
          if (this[list + "Map"].size) {
              return this[list + "Map"].get(code);
          }
      },
       containpichange(file) {
          let _this = this;
          if (this.imagebefore(file)) {
              _this.changeflag = true;
              this.PicImageUrl = URL.createObjectURL(file.raw);
              console.info("this.PicImageUrl=="+this.PicImageUrl);
              var reader = new FileReader();
              reader.readAsDataURL(file.raw);
              reader.onload = function () {
                  _this.ReqGroupList.containpic = reader.result.toString();
                  _this.ReqGroupList.containpic_type = file.name.split(".")[1].toString();
              };
              reader.onerror = function (error) {
                  console.log("Error: ", error);
              };
          }
      },
      imagebefore(file) {
          const isLt2M = file.size / 1024 / 1024 < 2;
          const isJPG = file.raw.type == "image/png" || file.raw.type == "image/jpeg" || file.raw.type == "image/jpg";
          if (!isJPG) {
              this.$message.error("只能上传图片格式(png,jpeg,jpg)!");
          }
          if (!isLt2M) {
              this.$message.error("上传图片大小不能超过 2MB!");
          }
          return isJPG && isLt2M;
      },
      previewPic(){
          this.imageurl = this.PicImageUrl;
          this.srcList.push(this.PicImageUrl) ;
          this.imagedialogVisible = true;
      },
      rowcontainpichange(file){
          let row = this.$refs.rigthxTable1.getCurrentRow();
          let _this = this;
          if (this.imagebefore(file)) {
              _this.changeflag = true;
              row.containpicurl = URL.createObjectURL(file.raw);
            //  console.info("this.PicImageUrl=="+this.PicImageUrl);
              var reader = new FileReader();
              reader.readAsDataURL(file.raw);
              reader.onload = function () {
                 row.containpic = reader.result.toString();
                 row.containpic_type = file.name.split(".")[1].toString();
              };
              reader.onerror = function (error) {
                  console.log("Error: ", error);
              };
          }
      },
      viewimage(row){
          this.imageurl = row.containpicurl;
          this.srcList.push(row.containpicurl) ;
          this.imagedialogVisible = true;
      },
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 75px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  overflow-x: auto;
  word-wrap: none;
  z-index: 99;
}
.pagecenter {
  position: absolute;
  top: 80px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: hidden;
}

.formtablestyle {
  height: 100%;
  font-size: 12px;
  color: #333;
  width: 100%;
}

.formtablestyle tr td:nth-child(1),
td:nth-child(3),
td:nth-child(5) {
  text-align: right;
}

.popTableStyle tr td:nth-child(1),
td:nth-child(3),
td:nth-child(5),
td:nth-child(7) {
  text-align: right;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader-icon1 {
  font-size: 28px;
  color: #8c939d;
  width: 175px;
  height: 35px;
  line-height: 35px;
  text-align: center;
}

.avatar-uploader-icon2{
  font-size: 14px;
  color: #8c939d;
  width: 50px;
  height: 23px;
  line-height: 23px;
  text-align: center;
}

.avatar {
  width: 178px;
  height: 50px;
  display: block;
}

.table1style tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
  width: 80px;
}
.table1style tr td:nth-child(even) {
  text-align: left;
}
.table1style tr td {
  padding: 0px 2px 0px 2px;
}

/deep/.el-color-picker--small .el-color-picker__trigger {
  width: 100% !important;
  height: 24px !important;
  padding: 0px;
}

/deep/.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner::after {
  border-color: #000000;
}

/deep/ .mytable-style.vxe-table .vxe-body--column.col-orange {
  background-color: #f8f8f8;
}

/deep/ .xTable1Class .vxe-table .vxe-cell {
  padding: 0px;
}

/deep/ .el-button.is-disabled {
  border: 0px;
  color: grey;
  background-color: #e6e6e6;
  font-weight: normal;
}

/deep/ .note-text .el-textarea__inner {
  padding: 5px !important;
}

/deep/ .btnclass {
  color: #000;
  background-color: #f3f7f9;
  font-weight: bold;
  border: 1px solid #c0c0c0;
  box-shadow: 1px 2px 1px #ddd;
}

table tr td:nth-child(odd) {
  text-align: right;
  white-space: nowrap;
}
table tr td:nth-child(even) {
  text-align: left;
}
table tr td:nth-child(1) {
  width: 80px;
}
table {
  font-size: 12px;
  border-collapse: separate;
  border-spacing: 5px;
}
</style>
